<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.10.0" />
<title>silk.config.core API documentation</title>
<meta name="description" content="" />
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/sanitize.min.css" integrity="sha256-PK9q560IAAa6WVRRh76LtCaI8pjTJ2z11v0miyNNjrs=" crossorigin>
<link rel="preload stylesheet" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/10up-sanitize.css/11.0.1/typography.min.css" integrity="sha256-7l/o7C8jubJiy74VsKTidCy1yBkRtiUGbVkYBylBqUg=" crossorigin>
<link rel="stylesheet preload" as="style" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/styles/github.min.css" crossorigin>
<style>:root{--highlight-color:#fe9}.flex{display:flex !important}body{line-height:1.5em}#content{padding:20px}#sidebar{padding:30px;overflow:hidden}#sidebar > *:last-child{margin-bottom:2cm}.http-server-breadcrumbs{font-size:130%;margin:0 0 15px 0}#footer{font-size:.75em;padding:5px 30px;border-top:1px solid #ddd;text-align:right}#footer p{margin:0 0 0 1em;display:inline-block}#footer p:last-child{margin-right:30px}h1,h2,h3,h4,h5{font-weight:300}h1{font-size:2.5em;line-height:1.1em}h2{font-size:1.75em;margin:1em 0 .50em 0}h3{font-size:1.4em;margin:25px 0 10px 0}h4{margin:0;font-size:105%}h1:target,h2:target,h3:target,h4:target,h5:target,h6:target{background:var(--highlight-color);padding:.2em 0}a{color:#058;text-decoration:none;transition:color .3s ease-in-out}a:hover{color:#e82}.title code{font-weight:bold}h2[id^="header-"]{margin-top:2em}.ident{color:#900}pre code{background:#f8f8f8;font-size:.8em;line-height:1.4em}code{background:#f2f2f1;padding:1px 4px;overflow-wrap:break-word}h1 code{background:transparent}pre{background:#f8f8f8;border:0;border-top:1px solid #ccc;border-bottom:1px solid #ccc;margin:1em 0;padding:1ex}#http-server-module-list{display:flex;flex-flow:column}#http-server-module-list div{display:flex}#http-server-module-list dt{min-width:10%}#http-server-module-list p{margin-top:0}.toc ul,#index{list-style-type:none;margin:0;padding:0}#index code{background:transparent}#index h3{border-bottom:1px solid #ddd}#index ul{padding:0}#index h4{margin-top:.6em;font-weight:bold}@media (min-width:200ex){#index .two-column{column-count:2}}@media (min-width:300ex){#index .two-column{column-count:3}}dl{margin-bottom:2em}dl dl:last-child{margin-bottom:4em}dd{margin:0 0 1em 3em}#header-classes + dl > dd{margin-bottom:3em}dd dd{margin-left:2em}dd p{margin:10px 0}.name{background:#eee;font-weight:bold;font-size:.85em;padding:5px 10px;display:inline-block;min-width:40%}.name:hover{background:#e0e0e0}dt:target .name{background:var(--highlight-color)}.name > span:first-child{white-space:nowrap}.name.class > span:nth-child(2){margin-left:.4em}.inherited{color:#999;border-left:5px solid #eee;padding-left:1em}.inheritance em{font-style:normal;font-weight:bold}.desc h2{font-weight:400;font-size:1.25em}.desc h3{font-size:1em}.desc dt code{background:inherit}.source summary,.git-link-div{color:#666;text-align:right;font-weight:400;font-size:.8em;text-transform:uppercase}.source summary > *{white-space:nowrap;cursor:pointer}.git-link{color:inherit;margin-left:1em}.source pre{max-height:500px;overflow:auto;margin:0}.source pre code{font-size:12px;overflow:visible}.hlist{list-style:none}.hlist li{display:inline}.hlist li:after{content:',\2002'}.hlist li:last-child:after{content:none}.hlist .hlist{display:inline;padding-left:1em}img{max-width:100%}td{padding:0 .5em}.admonition{padding:.1em .5em;margin-bottom:1em}.admonition-title{font-weight:bold}.admonition.note,.admonition.info,.admonition.important{background:#aef}.admonition.todo,.admonition.versionadded,.admonition.tip,.admonition.hint{background:#dfd}.admonition.warning,.admonition.versionchanged,.admonition.deprecated{background:#fd4}.admonition.error,.admonition.danger,.admonition.caution{background:lightpink}</style>
<style media="screen and (min-width: 700px)">@media screen and (min-width:700px){#sidebar{width:30%;height:100vh;overflow:auto;position:sticky;top:0}#content{width:70%;max-width:100ch;padding:3em 4em;border-left:1px solid #ddd}pre code{font-size:1em}.item .name{font-size:1em}main{display:flex;flex-direction:row-reverse;justify-content:flex-end}.toc ul ul,#index ul{padding-left:1.5em}.toc > ul > li{margin-top:.5em}}</style>
<style media="print">@media print{#sidebar h1{page-break-before:always}.source{display:none}}@media print{*{background:transparent !important;color:#000 !important;box-shadow:none !important;text-shadow:none !important}a[href]:after{content:" (" attr(href) ")";font-size:90%}a[href][title]:after{content:none}abbr[title]:after{content:" (" attr(title) ")"}.ir a:after,a[href^="javascript:"]:after,a[href^="#"]:after{content:""}pre,blockquote{border:1px solid #999;page-break-inside:avoid}thead{display:table-header-group}tr,img{page-break-inside:avoid}img{max-width:100% !important}@page{margin:0.5cm}p,h2,h3{orphans:3;widows:3}h1,h2,h3,h4,h5,h6{page-break-after:avoid}}</style>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.1.1/highlight.min.js" integrity="sha256-Uv3H6lx7dJmRfRvH8TH6kJD1TSK1aFcwgx+mdg3epi8=" crossorigin></script>
<script>window.addEventListener('DOMContentLoaded', () => hljs.initHighlighting())</script>
</head>
<body>
<main>
<article id="content">
<header>
<h1 class="title">Module <code>silk.config.core</code></h1>
</header>
<section id="section-intro">
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python"># Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.

# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.

from typing import Union, Callable, Any

import hydra.utils
from omegaconf import DictConfig, ListConfig

TargetType = Union[str, type, Callable[..., Any]]
ClassOrCallableType = Union[type, Callable[..., Any]]


def locate(path: str) -&gt; Any:
    &#34;&#34;&#34;
    Locate an object by name or dotted path, importing as necessary.
    This is similar to the pydoc function `locate`, except that it checks for
    the module from the given path from back to front.

    Parameters
    ----------
    path : str
        `module.path` path of the target to locate.

    Returns
    -------
    Any
        The value found at `path`.

    Raises
    ------
    ImportError
        Raised when empty path is provided.
    ImportError
        Raised when loading a module subpath has errors.
    &#34;&#34;&#34;

    if path == &#34;&#34;:
        raise ImportError(&#34;Empty path&#34;)

    import builtins
    from importlib import import_module

    parts = [part for part in path.split(&#34;.&#34;) if part]

    # load module part
    module = None
    for n in reversed(range(len(parts))):
        try:
            mod = &#34;.&#34;.join(parts[:n])
            module = import_module(mod)
        except Exception as e:
            if n == 0:
                raise ImportError(f&#34;Error loading module &#39;{path}&#39;&#34;) from e
            continue
        if module:
            break

    if module:
        obj = module
    else:
        obj = builtins

    # load object path in module
    for part in parts[n:]:
        mod = mod + &#34;.&#34; + part
        if not hasattr(obj, part):
            try:
                import_module(mod)
            except Exception as e:
                raise ImportError(
                    f&#34;Encountered error: `{e}` when loading module &#39;{path}&#39;&#34;
                ) from e
        obj = getattr(obj, part)

    return obj


def find_class_or_callable_from_target(
    target: TargetType,
) -&gt; ClassOrCallableType:
    &#34;&#34;&#34;Finds class or callable from its full module path. Do nothing if the input is already a class or callable.

    Parameters
    ----------
    target : TargetType
        Full module path.

    Returns
    -------
    ClassOrCallableType
        Class or callable found at target path.
    &#34;&#34;&#34;
    if isinstance(target, str):
        obj = locate(target)
    else:
        obj = target

    if (not isinstance(obj, type)) and (not callable(obj)):
        raise ValueError(f&#34;Invalid type ({type(obj)}) found for {target}&#34;)

    return obj


def find_and_ensure_is_subclass(target: TargetType, type_: type) -&gt; ClassOrCallableType:
    &#34;&#34;&#34;Find class from its full module path. Then checks if it is a subclass of a specific type.

    Parameters
    ----------
    target : TargetType
        Full module path.
    type_ : type
        Type to check for.

    Returns
    -------
    ClassOrCallableType
        Class or callable found at target path.
    &#34;&#34;&#34;
    klass = find_class_or_callable_from_target(target)
    ensure_is_subclass(klass, type_)
    return klass


def find_and_ensure_is_instance(target: TargetType, type_: type):
    &#34;&#34;&#34;Find item from its full module path. Then checks if it implements a specific type.

    Parameters
    ----------
    target : TargetType
        Full module path.
    type_ : type
        Type to check for.

    Returns
    -------
    ClassOrCallableType
        Class or callable found at target path.
    &#34;&#34;&#34;
    instance = find_class_or_callable_from_target(target)
    ensure_is_instance(instance, type_)
    return instance


def instantiate_and_ensure_is_instance(
    cfg: Union[DictConfig, ListConfig], type_: type
) -&gt; Any:
    &#34;&#34;&#34;Instantiate item from its config specification (hydra _target_ field). Then checks if it implements a specific type.

    Parameters
    ----------
    cfg : DictConfig
        Hydra dictionary container a `_target_` field.
    type_ : type
        Type to check for.

    Returns
    -------
    ClassOrCallableType
        Class or callable found at target path.
    &#34;&#34;&#34;
    instance = instantiate(cfg)
    ensure_is_instance(instance, type_)
    return instance


def instantiate(cfg: Union[DictConfig, ListConfig]):
    if isinstance(cfg, ListConfig):
        return [instantiate(item) for item in cfg]
    return hydra.utils.instantiate(cfg)


def full_instance_name(instance: Any) -&gt; str:
    &#34;&#34;&#34;Get full module path name of instance.

    Parameters
    ----------
    instance : Any
        Any object.

    Returns
    -------
    str
        Full module path name (e.g. `&lt;module&gt;.&lt;name&gt;`).
    &#34;&#34;&#34;
    return full_class_name(instance.__class__)


def full_class_name(klass: Any) -&gt; str:
    &#34;&#34;&#34;Get full module path name of class.

    Parameters
    ----------
    klass : Any
        Any class.

    Returns
    -------
    str
        Full module path name (e.g. `&lt;module&gt;.&lt;name&gt;`).
    &#34;&#34;&#34;
    module = klass.__module__
    if module == &#34;builtins&#34;:
        return klass.__qualname__  # avoid outputs like &#39;builtins.str&#39;
    return module + &#34;.&#34; + klass.__qualname__


def ensure_is_subclass(child_class: type, parent_class: type) -&gt; None:
    &#34;&#34;&#34;Make sure a class is a subclass of another. Raise exception otherwise.

    Parameters
    ----------
    child_class : type
        Child class
    parent_class : type
        Parent class

    Raises
    ------
    RuntimeError
        Raised when `child_class` is not a subclass of `parent_class`.
    &#34;&#34;&#34;
    if not issubclass(child_class, parent_class):
        raise RuntimeError(
            f&#34;class {full_class_name(child_class)} should be a subclass of {full_class_name(parent_class)}&#34;
        )


def ensure_is_instance(instance: Any, type_: type) -&gt; None:
    &#34;&#34;&#34;Make sure an object is an instance of a specifc class. Raise exception otherwise.

    Parameters
    ----------
    instance : Any
        Object to check for
    type_ : type
        Type to check for

    Raises
    ------
    RuntimeError
        Raised when `instance` is not an instance of `type_`.
    &#34;&#34;&#34;
    if not isinstance(instance, type_):
        raise RuntimeError(
            f&#34;instance should be of type {full_class_name(type_)}, not {full_instance_name(instance)}&#34;
        )</code></pre>
</details>
</section>
<section>
</section>
<section>
</section>
<section>
<h2 class="section-title" id="header-functions">Functions</h2>
<dl>
<dt id="silk.config.core.ensure_is_instance"><code class="name flex">
<span>def <span class="ident">ensure_is_instance</span></span>(<span>instance: Any, type_: type) ‑> None</span>
</code></dt>
<dd>
<div class="desc"><p>Make sure an object is an instance of a specifc class. Raise exception otherwise.</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>instance</code></strong> :&ensp;<code>Any</code></dt>
<dd>Object to check for</dd>
<dt><strong><code>type_</code></strong> :&ensp;<code>type</code></dt>
<dd>Type to check for</dd>
</dl>
<h2 id="raises">Raises</h2>
<dl>
<dt><code>RuntimeError</code></dt>
<dd>Raised when <code>instance</code> is not an instance of <code>type_</code>.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def ensure_is_instance(instance: Any, type_: type) -&gt; None:
    &#34;&#34;&#34;Make sure an object is an instance of a specifc class. Raise exception otherwise.

    Parameters
    ----------
    instance : Any
        Object to check for
    type_ : type
        Type to check for

    Raises
    ------
    RuntimeError
        Raised when `instance` is not an instance of `type_`.
    &#34;&#34;&#34;
    if not isinstance(instance, type_):
        raise RuntimeError(
            f&#34;instance should be of type {full_class_name(type_)}, not {full_instance_name(instance)}&#34;
        )</code></pre>
</details>
</dd>
<dt id="silk.config.core.ensure_is_subclass"><code class="name flex">
<span>def <span class="ident">ensure_is_subclass</span></span>(<span>child_class: type, parent_class: type) ‑> None</span>
</code></dt>
<dd>
<div class="desc"><p>Make sure a class is a subclass of another. Raise exception otherwise.</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>child_class</code></strong> :&ensp;<code>type</code></dt>
<dd>Child class</dd>
<dt><strong><code>parent_class</code></strong> :&ensp;<code>type</code></dt>
<dd>Parent class</dd>
</dl>
<h2 id="raises">Raises</h2>
<dl>
<dt><code>RuntimeError</code></dt>
<dd>Raised when <code>child_class</code> is not a subclass of <code>parent_class</code>.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def ensure_is_subclass(child_class: type, parent_class: type) -&gt; None:
    &#34;&#34;&#34;Make sure a class is a subclass of another. Raise exception otherwise.

    Parameters
    ----------
    child_class : type
        Child class
    parent_class : type
        Parent class

    Raises
    ------
    RuntimeError
        Raised when `child_class` is not a subclass of `parent_class`.
    &#34;&#34;&#34;
    if not issubclass(child_class, parent_class):
        raise RuntimeError(
            f&#34;class {full_class_name(child_class)} should be a subclass of {full_class_name(parent_class)}&#34;
        )</code></pre>
</details>
</dd>
<dt id="silk.config.core.find_and_ensure_is_instance"><code class="name flex">
<span>def <span class="ident">find_and_ensure_is_instance</span></span>(<span>target: Union[str, type, Callable[..., Any]], type_: type)</span>
</code></dt>
<dd>
<div class="desc"><p>Find item from its full module path. Then checks if it implements a specific type.</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>target</code></strong> :&ensp;<code>TargetType</code></dt>
<dd>Full module path.</dd>
<dt><strong><code>type_</code></strong> :&ensp;<code>type</code></dt>
<dd>Type to check for.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>ClassOrCallableType</code></dt>
<dd>Class or callable found at target path.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def find_and_ensure_is_instance(target: TargetType, type_: type):
    &#34;&#34;&#34;Find item from its full module path. Then checks if it implements a specific type.

    Parameters
    ----------
    target : TargetType
        Full module path.
    type_ : type
        Type to check for.

    Returns
    -------
    ClassOrCallableType
        Class or callable found at target path.
    &#34;&#34;&#34;
    instance = find_class_or_callable_from_target(target)
    ensure_is_instance(instance, type_)
    return instance</code></pre>
</details>
</dd>
<dt id="silk.config.core.find_and_ensure_is_subclass"><code class="name flex">
<span>def <span class="ident">find_and_ensure_is_subclass</span></span>(<span>target: Union[str, type, Callable[..., Any]], type_: type) ‑> Union[type, Callable[..., Any]]</span>
</code></dt>
<dd>
<div class="desc"><p>Find class from its full module path. Then checks if it is a subclass of a specific type.</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>target</code></strong> :&ensp;<code>TargetType</code></dt>
<dd>Full module path.</dd>
<dt><strong><code>type_</code></strong> :&ensp;<code>type</code></dt>
<dd>Type to check for.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>ClassOrCallableType</code></dt>
<dd>Class or callable found at target path.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def find_and_ensure_is_subclass(target: TargetType, type_: type) -&gt; ClassOrCallableType:
    &#34;&#34;&#34;Find class from its full module path. Then checks if it is a subclass of a specific type.

    Parameters
    ----------
    target : TargetType
        Full module path.
    type_ : type
        Type to check for.

    Returns
    -------
    ClassOrCallableType
        Class or callable found at target path.
    &#34;&#34;&#34;
    klass = find_class_or_callable_from_target(target)
    ensure_is_subclass(klass, type_)
    return klass</code></pre>
</details>
</dd>
<dt id="silk.config.core.find_class_or_callable_from_target"><code class="name flex">
<span>def <span class="ident">find_class_or_callable_from_target</span></span>(<span>target: Union[str, type, Callable[..., Any]]) ‑> Union[type, Callable[..., Any]]</span>
</code></dt>
<dd>
<div class="desc"><p>Finds class or callable from its full module path. Do nothing if the input is already a class or callable.</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>target</code></strong> :&ensp;<code>TargetType</code></dt>
<dd>Full module path.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>ClassOrCallableType</code></dt>
<dd>Class or callable found at target path.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def find_class_or_callable_from_target(
    target: TargetType,
) -&gt; ClassOrCallableType:
    &#34;&#34;&#34;Finds class or callable from its full module path. Do nothing if the input is already a class or callable.

    Parameters
    ----------
    target : TargetType
        Full module path.

    Returns
    -------
    ClassOrCallableType
        Class or callable found at target path.
    &#34;&#34;&#34;
    if isinstance(target, str):
        obj = locate(target)
    else:
        obj = target

    if (not isinstance(obj, type)) and (not callable(obj)):
        raise ValueError(f&#34;Invalid type ({type(obj)}) found for {target}&#34;)

    return obj</code></pre>
</details>
</dd>
<dt id="silk.config.core.full_class_name"><code class="name flex">
<span>def <span class="ident">full_class_name</span></span>(<span>klass: Any) ‑> str</span>
</code></dt>
<dd>
<div class="desc"><p>Get full module path name of class.</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>klass</code></strong> :&ensp;<code>Any</code></dt>
<dd>Any class.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>str</code></dt>
<dd>Full module path name (e.g. <code>&lt;module&gt;.&lt;name&gt;</code>).</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def full_class_name(klass: Any) -&gt; str:
    &#34;&#34;&#34;Get full module path name of class.

    Parameters
    ----------
    klass : Any
        Any class.

    Returns
    -------
    str
        Full module path name (e.g. `&lt;module&gt;.&lt;name&gt;`).
    &#34;&#34;&#34;
    module = klass.__module__
    if module == &#34;builtins&#34;:
        return klass.__qualname__  # avoid outputs like &#39;builtins.str&#39;
    return module + &#34;.&#34; + klass.__qualname__</code></pre>
</details>
</dd>
<dt id="silk.config.core.full_instance_name"><code class="name flex">
<span>def <span class="ident">full_instance_name</span></span>(<span>instance: Any) ‑> str</span>
</code></dt>
<dd>
<div class="desc"><p>Get full module path name of instance.</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>instance</code></strong> :&ensp;<code>Any</code></dt>
<dd>Any object.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>str</code></dt>
<dd>Full module path name (e.g. <code>&lt;module&gt;.&lt;name&gt;</code>).</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def full_instance_name(instance: Any) -&gt; str:
    &#34;&#34;&#34;Get full module path name of instance.

    Parameters
    ----------
    instance : Any
        Any object.

    Returns
    -------
    str
        Full module path name (e.g. `&lt;module&gt;.&lt;name&gt;`).
    &#34;&#34;&#34;
    return full_class_name(instance.__class__)</code></pre>
</details>
</dd>
<dt id="silk.config.core.instantiate"><code class="name flex">
<span>def <span class="ident">instantiate</span></span>(<span>cfg: Union[omegaconf.dictconfig.DictConfig, omegaconf.listconfig.ListConfig])</span>
</code></dt>
<dd>
<div class="desc"></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def instantiate(cfg: Union[DictConfig, ListConfig]):
    if isinstance(cfg, ListConfig):
        return [instantiate(item) for item in cfg]
    return hydra.utils.instantiate(cfg)</code></pre>
</details>
</dd>
<dt id="silk.config.core.instantiate_and_ensure_is_instance"><code class="name flex">
<span>def <span class="ident">instantiate_and_ensure_is_instance</span></span>(<span>cfg: Union[omegaconf.dictconfig.DictConfig, omegaconf.listconfig.ListConfig], type_: type) ‑> Any</span>
</code></dt>
<dd>
<div class="desc"><p>Instantiate item from its config specification (hydra <em>target</em> field). Then checks if it implements a specific type.</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>cfg</code></strong> :&ensp;<code>DictConfig</code></dt>
<dd>Hydra dictionary container a <code>_target_</code> field.</dd>
<dt><strong><code>type_</code></strong> :&ensp;<code>type</code></dt>
<dd>Type to check for.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>ClassOrCallableType</code></dt>
<dd>Class or callable found at target path.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def instantiate_and_ensure_is_instance(
    cfg: Union[DictConfig, ListConfig], type_: type
) -&gt; Any:
    &#34;&#34;&#34;Instantiate item from its config specification (hydra _target_ field). Then checks if it implements a specific type.

    Parameters
    ----------
    cfg : DictConfig
        Hydra dictionary container a `_target_` field.
    type_ : type
        Type to check for.

    Returns
    -------
    ClassOrCallableType
        Class or callable found at target path.
    &#34;&#34;&#34;
    instance = instantiate(cfg)
    ensure_is_instance(instance, type_)
    return instance</code></pre>
</details>
</dd>
<dt id="silk.config.core.locate"><code class="name flex">
<span>def <span class="ident">locate</span></span>(<span>path: str) ‑> Any</span>
</code></dt>
<dd>
<div class="desc"><p>Locate an object by name or dotted path, importing as necessary.
This is similar to the pydoc function <code><a title="silk.config.core.locate" href="#silk.config.core.locate">locate()</a></code>, except that it checks for
the module from the given path from back to front.</p>
<h2 id="parameters">Parameters</h2>
<dl>
<dt><strong><code>path</code></strong> :&ensp;<code>str</code></dt>
<dd><code>module.path</code> path of the target to locate.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>Any</code></dt>
<dd>The value found at <code>path</code>.</dd>
</dl>
<h2 id="raises">Raises</h2>
<dl>
<dt><code>ImportError</code></dt>
<dd>Raised when empty path is provided.</dd>
<dt><code>ImportError</code></dt>
<dd>Raised when loading a module subpath has errors.</dd>
</dl></div>
<details class="source">
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">def locate(path: str) -&gt; Any:
    &#34;&#34;&#34;
    Locate an object by name or dotted path, importing as necessary.
    This is similar to the pydoc function `locate`, except that it checks for
    the module from the given path from back to front.

    Parameters
    ----------
    path : str
        `module.path` path of the target to locate.

    Returns
    -------
    Any
        The value found at `path`.

    Raises
    ------
    ImportError
        Raised when empty path is provided.
    ImportError
        Raised when loading a module subpath has errors.
    &#34;&#34;&#34;

    if path == &#34;&#34;:
        raise ImportError(&#34;Empty path&#34;)

    import builtins
    from importlib import import_module

    parts = [part for part in path.split(&#34;.&#34;) if part]

    # load module part
    module = None
    for n in reversed(range(len(parts))):
        try:
            mod = &#34;.&#34;.join(parts[:n])
            module = import_module(mod)
        except Exception as e:
            if n == 0:
                raise ImportError(f&#34;Error loading module &#39;{path}&#39;&#34;) from e
            continue
        if module:
            break

    if module:
        obj = module
    else:
        obj = builtins

    # load object path in module
    for part in parts[n:]:
        mod = mod + &#34;.&#34; + part
        if not hasattr(obj, part):
            try:
                import_module(mod)
            except Exception as e:
                raise ImportError(
                    f&#34;Encountered error: `{e}` when loading module &#39;{path}&#39;&#34;
                ) from e
        obj = getattr(obj, part)

    return obj</code></pre>
</details>
</dd>
</dl>
</section>
<section>
</section>
</article>
<nav id="sidebar">
<h1>Index</h1>
<div class="toc">
<ul></ul>
</div>
<ul id="index">
<li><h3>Super-module</h3>
<ul>
<li><code><a title="silk.config" href="index.html">silk.config</a></code></li>
</ul>
</li>
<li><h3><a href="#header-functions">Functions</a></h3>
<ul class="">
<li><code><a title="silk.config.core.ensure_is_instance" href="#silk.config.core.ensure_is_instance">ensure_is_instance</a></code></li>
<li><code><a title="silk.config.core.ensure_is_subclass" href="#silk.config.core.ensure_is_subclass">ensure_is_subclass</a></code></li>
<li><code><a title="silk.config.core.find_and_ensure_is_instance" href="#silk.config.core.find_and_ensure_is_instance">find_and_ensure_is_instance</a></code></li>
<li><code><a title="silk.config.core.find_and_ensure_is_subclass" href="#silk.config.core.find_and_ensure_is_subclass">find_and_ensure_is_subclass</a></code></li>
<li><code><a title="silk.config.core.find_class_or_callable_from_target" href="#silk.config.core.find_class_or_callable_from_target">find_class_or_callable_from_target</a></code></li>
<li><code><a title="silk.config.core.full_class_name" href="#silk.config.core.full_class_name">full_class_name</a></code></li>
<li><code><a title="silk.config.core.full_instance_name" href="#silk.config.core.full_instance_name">full_instance_name</a></code></li>
<li><code><a title="silk.config.core.instantiate" href="#silk.config.core.instantiate">instantiate</a></code></li>
<li><code><a title="silk.config.core.instantiate_and_ensure_is_instance" href="#silk.config.core.instantiate_and_ensure_is_instance">instantiate_and_ensure_is_instance</a></code></li>
<li><code><a title="silk.config.core.locate" href="#silk.config.core.locate">locate</a></code></li>
</ul>
</li>
</ul>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc" title="pdoc: Python API documentation generator"><cite>pdoc</cite> 0.10.0</a>.</p>
</footer>
</body>
</html>